package com.nai365.nart.pay.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq 配置类
 */
@Configuration
public class RabiitMQConfig {

	@Bean("payQueue")
	public Queue payQueue() {

		return QueueBuilder.durable("payQueue").build();
	}

	@Bean("payQueueExchange")
	DirectExchange payQueueExchange() {

		return  ExchangeBuilder.directExchange("payQueueExchange").build();
	}

	@Bean("payQueueBind")
	Binding bindingExchange(@Qualifier("payQueue") Queue payQueue, @Qualifier("payQueueExchange")DirectExchange payQueueExchange) {
		 return BindingBuilder.bind(payQueue).to(payQueueExchange).with("pay");

	}


//	public static final String BLOCKCHAIN_EXCHANGE = "blockchain-exchange";
//
//	public static final String TRANSFER_QUEUE = "blockchain.transfer";
//
//	public static final String TRANSFER_ROUTING_KEY = "blockchain.transfer";
//
//
//	@Primary
//	@Bean
//	public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
//		final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
//		rabbitTemplate.setMessageConverter(messageConverter());
//		return rabbitTemplate;
//	}
//
//	@Bean
//	public MessageConverter messageConverter() {
//		ObjectMapper om = new ObjectMapper();
//		om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//		om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
//		om.registerModule(new JavaTimeModule());
//		return new Jackson2JsonMessageConverter(om);
//	}
//
//
//	@Bean(BLOCKCHAIN_EXCHANGE)
//	public Exchange EXCHANGE_TOPICS_INFORM() {
//		return ExchangeBuilder.topicExchange(BLOCKCHAIN_EXCHANGE).durable(true).build();
//	}
//
//
//	@Bean(TRANSFER_QUEUE)
//	public Queue transferQueue() {
//		return new Queue(TRANSFER_QUEUE);
//	}
//
//
//	@Bean
//	public Binding transferQueueBinding(
//			@Qualifier(TRANSFER_QUEUE) Queue queue, @Qualifier(BLOCKCHAIN_EXCHANGE) Exchange exchange) {
//		return BindingBuilder.bind(queue).to(exchange).with(TRANSFER_ROUTING_KEY).noargs();
//	}

}



